<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<ui:composition template="/templates/template.xhtml">
	<ui:define name="pageTitle">Serviços</ui:define>
	<ui:define name="pageHeader">Listagem de Serviços</ui:define>
	<ui:define name="body">
		<h:panelGrid columns="1">
			<p:column>
				<p:commandButton action="#{servicoBean.novoServico()}"
					update=":form:janDetail" oncomplete="PF('janDialog').show()"
					value="Adicionar Serviços" style="margin-left:40px" />
			</p:column>
		</h:panelGrid>
		<h:form id="form">
			<p:growl id="msgs" />
			<p:dataTable id="dtServico" editable="true" paginator="true"
				value="#{servicoBean.lista}" var="servico" rows="5"
				style="font-size:12px;margin-top:10px"
				emptyMessage="Nenhum cadastro efetuado! ">

				<f:facet name="header">
					<h:outputText value="Lista de Serviços" />
				</f:facet>
				<p:column style="width:2%">
					<div align="center">
						<p:commandLink update=":form" action="#{servicoBean.setStatusCronograma()}"
							onclick="if(!confirm('Deseja adicionar o serviço ao CRONOGRAMA?')) return false;">
							<div align="center">
								<h:graphicImage
									url="#{servico.status == 1? '/templates/Imagens/icon_status_active.gif' : '/templates/Imagens/warning_a.gif'}" />
							</div>
							<f:setPropertyActionListener
								target="#{servicoBean.servicoSelecionado}" value="#{servico}" />
						</p:commandLink>

					</div>
				</p:column>
				<p:column width="5%" headerText="Código" style="font-size:12px;">
										#{servico.id}
									</p:column>
				<p:column headerText="Serviço" style="font-size:12px;">
										#{servico.nome}
									</p:column>
				<p:column headerText="Obra" style="font-size:12px;">
										#{servico.obra.nome}
									</p:column>
				<p:column headerText="% Peso" style="font-size:12px;">
										#{servico.peso}
									</p:column>

				<p:column style="width:2%">
					<div align="center">
						<p:commandLink update=":form"
							action="#{servicoBean.excluir(servico.id)}"
							onclick="if(!confirm('Deseja realmente excluir?')) return false;">
							<div align="center">
								<h:graphicImage url="/templates/Imagens/delete-2.png" />
							</div>
							<f:setPropertyActionListener
								target="#{servicoBean.servicoSelecionado}" value="#{servico}" />
						</p:commandLink>

					</div>
				</p:column>
				<p:column style="width:2%">
					<p:commandLink update=":form:janDetail"
						oncomplete="PF('janDialog').show()">
						<h:graphicImage url="/templates/Imagens/icon_pencil.png" />
						<f:setPropertyActionListener
							target="#{servicoBean.servicoSelecionado}" value="#{servico}" />
					</p:commandLink>

				</p:column>
			</p:dataTable>

			<p />
			<p />
			<p:dialog id="dlgServico" width="70%" height="100%"
				header="Gerênciador de Serviços" widgetVar="janDialog" modal="false"
				showEffect="fade" hideEffect="fade" resizable="false"
				appendToBody="true" draggable="false">


				<p:outputPanel id="janDetail" style="float: center;text-align:left;">
					<p:fieldset legend="Serviço:" toggleable="false"
						style="float: center;width:95%;font-size:12px;">

						<h:inputHidden value="#{servicoBean.servicoSelecionado.id}" />

						<h:panelGrid columns="2" id="pnServicoEdit"
							style="float: center;width:100%">
							<p:row>
								<p:column>
									<h:outputLabel value="Obra:"
										style="float: left;width:40%; font-weight: bold;font-size:12px;" />
								</p:column>
								<p:column>
									<p:selectOneMenu value="#{servicoBean.obraSelecionada}"
										required="true">
										<f:selectItems value="#{servicoBean.obrasSelect}" />
									</p:selectOneMenu>
									<h:outputLabel value=" *"
										style="font-weight: bold;font-size:18px;color:red" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputLabel id="lblServico" value="Nome do Serviço:"
										style="float: left;width:40%; font-weight: bold;font-size:12px;" />
								</p:column>
								<p:column>
									<p:inputText id="txtServico" converter="toUpperCaseConverter"
										value="#{servicoBean.servicoSelecionado.nome}">
									</p:inputText>
									<h:outputLabel value=" *"
										style="font-weight: bold;font-size:18px;color:red" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputLabel id="lblPeso" value="Peso:"
										style="float: left;width:40%; font-weight: bold;font-size:12px;" />
								</p:column>
								<p:column>
									<p:inputText id="txtPeso"
										value="#{servicoBean.servicoSelecionado.peso}" />

									<h:outputLabel value=" *"
										style="font-weight: bold;font-size:18px;color:red" />
								</p:column>
							</p:row>
							<p:row>
								<p:column>
									<h:outputLabel id="lblPercExec" value="% Executado:"
										style="float: left;width:40%; font-weight: bold;font-size:12px;" />
								</p:column>
								<p:column>
									<p:inputText id="txtPercExec" required="false"
										value="#{servicoBean.servicoSelecionado.percExecutado}" />
								</p:column>
							</p:row>
						</h:panelGrid>
						<div align="right" style="margin-right: 4%">
							<h:commandButton value="Salvar" ajax="true" update=":form"
								action="#{servicoBean.salvar()}"
								oncomplete="handleLoginRequest(xhr, status, args)" />
						</div>

					</p:fieldset>
				</p:outputPanel>
			</p:dialog>
		</h:form>
		<script type="text/javascript">
    function handleLoginRequest(xhr, status, args) {
        if(args.validationFailed) {
            PF('janDialog').jq.effect("shake", {times:5}, 100);
        }
        else {
            PF('janDialog').hide();
            $('#loginLink').fadeOut();
        }
    }
</script>
	</ui:define>
</ui:composition>

</html>